package cn.tyz.kotlin.glide

import android.content.Context
import com.bumptech.glide.GlideBuilder
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.load.engine.cache.LruResourceCache
import com.bumptech.glide.module.AppGlideModule
import java.io.InputStream

/**
 * @author : tianyingzhong
 * @ClassName: CustomAppGlideModule
 * @Description:
 * @time 2017/8/23 19:56
 */
@GlideModule
internal class CustomAppGlideModule : AppGlideModule() {
    /**
     * 设置内存缓存大小10M
     */
    val  cacheSize=10*1024*1024
    override fun applyOptions(context: Context?, builder: GlideBuilder) {
        builder.setMemoryCache(LruResourceCache(cacheSize))
    }

    /**
     * 注册一个String类型的BaseGlideUrlLoader
     */
    override fun registerComponents(context: Context?, registry: Registry) {

        registry.append(String::class.java, InputStream::class.java,
                CustomBaseGlideUrlLoader.factory)
    }

    /**
     * 关闭解析AndroidManifest
     */
    override fun isManifestParsingEnabled(): Boolean {
        return false
    }

}